package com.littleu.market.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.littleu.market.common.constant.IdentityConstant;
import com.littleu.market.mapper.UserIdendityMapper;
import com.littleu.market.model.UserIdentityDO;
import com.littleu.market.service.IUserIdentityService;
import io.github.talelin.core.util.EncryptUtil;
import org.springframework.stereotype.Service;

@Service
public class UserIdentityImpl extends ServiceImpl<UserIdendityMapper, UserIdentityDO> implements IUserIdentityService {
    @Override
    public boolean verifyUsernamePassword(Integer userId, String username, String password) {
        QueryWrapper<UserIdentityDO> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserIdentityDO::getUserId, userId)
                .eq(UserIdentityDO::getIdentityType, IdentityConstant.USERNAME_PASSWORD_IDENTITY)
                .eq(UserIdentityDO::getIdentifier, username);
        UserIdentityDO userIdentityDO = this.baseMapper.selectOne(wrapper);
        return EncryptUtil.verify(userIdentityDO.getCredential(), password);
    }
}
